﻿// -----------------------------------------------------------------------------
// ABC 是 .NET 6 平台下开发管理的系统。
// 重庆虫儿飞科技有限公司 © 2022 ABC.Admin
// 框架：基于 Furion + SqlSugar 的后台框架：ABC.Admin
// -----------------------------------------------------------------------------

using Microsoft.AspNetCore.Http;

namespace Abc.Base;

public static class SessionHelper
{
    /// <summary>
    /// 删除Session
    /// </summary>
    /// <param name="key"></param>
    public static void Clear(string key)
    {
        App.HttpContext.DeleteSession(key);
    }

    /// <summary>
    /// 获取Session值
    /// </summary>
    /// <param name="key"></param>
    /// <returns></returns>
    public static string Get(string key, string encryptKey = "")
    {
        return App.HttpContext.GetSessionValue(key, encryptKey);
    }

    /// <summary>
    /// 获取Session值
    /// </summary>
    /// <param name="key"></param>
    /// <returns></returns>
    public static T Get<T>(string key, string encryptKey = "")
    {
        return App.HttpContext.GetSessionValue<T>(key, encryptKey);
    }

    /// <summary>
    /// 设置Session（默认关闭浏览器失效）
    /// </summary>
    /// <param name="key"></param>
    /// <param name="value"></param>
    /// <param name="encryptKey">加密密钥（长度为32的2次方数）</param>
    public static void Set(string key, string value, string encryptKey = "")
    {
        App.HttpContext.SetSession(key, value, encryptKey);
    }

  
}